package com.decrypt;

import com.custom.CharacterUtil;
import org.apache.commons.lang3.ObjectUtils;

import java.security.MessageDigest;

public class Md5Util {

    public static String encrypt(String content) {
        try {
            MessageDigest digest = MessageDigest.getInstance("MD5");
            digest.reset();
            digest.update(content.getBytes(CharacterUtil.UTF_8));
            byte[] engineDigest = digest.digest();
            if (ObjectUtils.isEmpty(engineDigest)) {
                return null;
            }
            StringBuffer buffer = new StringBuffer(engineDigest.length * 2);
            for (int i = 0; i < engineDigest.length; i++) {
                if ((engineDigest[i] & 0xff) < 0x10) {
                    buffer.append("0");
                }
                buffer.append(Long.toString(engineDigest[i] & 0xff, 16));
            }
            return buffer.toString();
        } catch (Exception e) {
            return null;
        }
    }

    public static void main(String[] args) {
        String encrypt = encrypt("Aa111111");
        System.out.println(encrypt);
    }

}
